class TreeNode{
    val = null;
    left = null;
    right = null;
    static new(val){
        var treeNode = TreeNode();
        treeNode.val = val;
        return treeNode;
    }
}


# 伪造链表
var root = TreeNode.new(2);
var left = TreeNode.new(1);
var right = TreeNode.new(3);
root.left = left;
root.right = right;

# 定义函数 递归翻转函数
function invertTree(root) {
    if (root == null) return null;
    var temp = root.left;
    root.left = root.right;
    root.right = temp;
    invertTree(root.left);
    invertTree(root.right);
    return root;
}

# 打印结果
print(invertTree(root));